#!/usr/bin/python
from __future__ import print_function
import sys
import os

if len(sys.argv) != 3:
    print('Usage: pre_seg_sen.py lan_dir out_dir')
    sys.exit(1)
elif not os.path.isdir(sys.argv[1]):
    print('Error: %s is not a validate directory!' % sys.argv[1])
elif not os.path.exists(sys.argv[2]):
    print('Warning: %s desn\'t exists, create it for you' % sys.argv[2])
    os.makedirs(sys.argv[2])
else:
    print('preprocess for sentence segment')

for filename in os.listdir(sys.argv[1]):
    src_full_name = os.path.join(sys.argv[1], filename)
    print("preprocess %s" % src_full_name)
    with open(src_full_name, 'r') as fr, open(os.path.join(sys.argv[2], filename), 'w') as fw:
        lines = fr.readlines()
        for line in lines:
            if len(line.strip()):    # line not empty or only space character
                if not line.strip().endswith('.'):   #for every line, not endwith '.' char
                    line = line.strip() + '.'
                print(line, file=fw)

print("preprocess for sentence segment done!")

